//////////////////////////////////////////
//
//	FlexInc. 2011
//	http://www.loziosecchi.it/flex_inc
//	http://twitter.com/loziosecchi
//
//////////////////////////////////////////

package flexInc.spark.effects
{
	import flash.display.BitmapData;
	import flash.geom.Point;
	
	import mx.core.IVisualElementContainer;
	
	import spark.effects.Animate;
	import spark.effects.AnimateTransitionShader;
	import spark.effects.CrossFade;
	import spark.effects.Wipe;
	
	/**
	 * The AnimateTransitionShaderUtils effect uses Pixel Bender,
	 * which is not supported for AIR mobile applications.
	 */
	[DiscouragedForProfile("mobileDevice")]
	
	/**
	 * The AnimateTransitionShaderUtils is a utility class used
	 * to get an <code>AnimateTransitionShader</code>
	 * depending on a string type and a list of
	 * parameters.
	 */
	public class AnimateTransitionShaderUtils
	{
		/**
		 *  The circular wipe animation type
		 */
		public static const CIRCLE_WIPE:String = "circle_wipe";
		
		/**
		 *  The corona animation type
		 */
		public static const CORONA:String = "corona";
		
		/**
		 *  The crossfade animation type
		 */
		public static const CROSS_FADE:String = "cross_fade";
		
		/**
		 *  The crossfade animation type
		 */
		public static const CROSS_WIPE:String = "cross_wipe";
		
		/**
		 *  The mosaic animation type
		 */
		public static const MOSAIC:String = "mosaic";
		
		/**
		 *  The push animation type
		 */
		public static const PUSH:String = "push";
		
		/**
		 *  The rectangular wipe animation type
		 */
		public static const RECT_WIPE:String = "rect_wipe";
		
		/**
		 *  The spotlight animation type
		 */
		public static const SPOTLIGHT:String = "spotlight";
		
		/**
		 *  The white crossfade animation type
		 */
		public static const WHITE_CROSS_FADE:String = "white_cross_fade";
		
		/**
		 *  The wipe animation type
		 */
		public static const WIPE:String = "wipe";
		
		/**
		 * Returns a transition depending on a string type
		 * and a list of parameters.
		 */
		public static function getTransition(type:String, target:IVisualElementContainer, params:* = null):AnimateTransitionShader
		{
			var shader:AnimateTransitionShader;
			
			switch(type)
			{
				case WIPE:
					shader = getWipe(params);
					break;
				case CIRCLE_WIPE:
					shader = getCircleWipe(params);
					break;
				case RECT_WIPE:
					shader = getRectWipe(params);
					break;
				case CROSS_FADE:
					shader = getCrossFade(params);
					break;
				case WHITE_CROSS_FADE:
					shader = getWhiteCrossFade(params);
					break;
				case MOSAIC:
					shader = getMosaic(params);
					break;
				case CORONA:
					shader = getCorona(params);
					break;
				case SPOTLIGHT:
					shader = getSpotlight(params);
					break;
				case PUSH:
					shader = getPush(params);
					break;
				case CROSS_WIPE:
					shader = getCrossWipe(params);
					break;
				default:
					throw new Error("No AnimateTransitionShader of type " + type + ".");
					break;
			}
			shader.target = target;
			
			return shader;
		}
		
		/**
		 * Returns a <code>Wipe</code> transition depending on a string type
		 * and a list of parameters.
		 */
		public static function getWipe(params:* = null):Wipe
		{
			var effect:Wipe = new Wipe();
			
			effect.direction = params.direction;
			effect.easer = EaserUtils.getEaser(params.easer);
			
			if(params.duration && params.duration > 0)
				effect.duration = params.duration;
			
			return effect;
		}
		
		/**
		 * Returns a <code>CircleWipe</code> transition depending on a string type
		 * and a list of parameters.
		 */
		public static function getCircleWipe(params:* = null):CircleWipe
		{
			var effect:CircleWipe = new CircleWipe();
			
			effect.direction = params.direction;
			effect.easer = EaserUtils.getEaser(params.easer);
			
			if(params.duration && params.duration > 0)
				effect.duration = params.duration;
			
			var center:Point = new Point(0, 0);
			if(params.center_x)
				center.x = params.center_x;
			if(params.center_y)
				center.y = params.center_y;			
			effect.center = center;
			
			return effect;
		}
		
		/**
		 * Returns a <code>RectWipe</code> transition depending on a string type
		 * and a list of parameters.
		 */
		public static function getRectWipe(params:* = null):RectWipe
		{
			var effect:RectWipe = new RectWipe();
			
			effect.direction = params.direction;
			effect.easer = EaserUtils.getEaser(params.easer);
			
			if(params.duration && params.duration > 0)
				effect.duration = params.duration;
			
			var center:Point = new Point(0, 0);
			if(params.center_x)
				center.x = params.center_x;
			if(params.center_y)
				center.y = params.center_y;			
			effect.center = center;
			
			return effect;
		}
		/**
		 * Returns a <code>CrossWipe</code> transition depending on a string type
		 * and a list of parameters.
		 */
		public static function getCrossWipe(params:* = null):CrossWipe
		{
			var effect:CrossWipe = new CrossWipe();
			
			effect.direction = params.direction;
			effect.easer = EaserUtils.getEaser(params.easer);
			
			if(params.duration && params.duration > 0)
				effect.duration = params.duration;
			
			var center:Point = new Point(0, 0);
			if(params.center_x)
				center.x = params.center_x;
			if(params.center_y)
				center.y = params.center_y;			
			effect.center = center;
			
			return effect;
		}
		
		/**
		 * Returns a <code>CrossFade</code> transition depending on a string type
		 * and a list of parameters.
		 */
		public static function getCrossFade(params:* = null):CrossFade
		{
			var effect:CrossFade = new CrossFade();
			
			effect.easer = EaserUtils.getEaser(params.easer);
			
			if(params.duration && params.duration > 0)
				effect.duration = params.duration;
			
			return effect;
		}
		
		/**
		 * Returns a <code>WhiteCrossFade</code> transition depending on a string type
		 * and a list of parameters.
		 */
		public static function getWhiteCrossFade(params:* = null):WhiteCrossFade
		{
			var effect:WhiteCrossFade = new WhiteCrossFade();
			
			effect.easer = EaserUtils.getEaser(params.easer);
			
			if(params.duration && params.duration > 0)
				effect.duration = params.duration;
			
			return effect;
		}
		
		/**
		 * Returns a <code>Mosaic</code> transition depending on a string type
		 * and a list of parameters.
		 */
		public static function getMosaic(params:* = null):Mosaic
		{
			var effect:Mosaic = new Mosaic();
			
			effect.easer = EaserUtils.getEaser(params.easer);
			
			if(params.duration && params.duration > 0)
				effect.duration = params.duration;
			
			if(params.type)
				effect.type = params.type;
			
			if(params.max_pixelization_size && params.max_pixelization_size > 0)
				effect.maxPixelizationSize = params.max_pixelization_size;
			
			return effect;
		}
		
		/**
		 * Returns a <code>Corona</code> transition depending on a string type
		 * and a list of parameters.
		 */
		public static function getCorona(params:* = null):Corona
		{
			var effect:Corona = new Corona();
			
			effect.easer = EaserUtils.getEaser(params.easer);
			
			if(params.duration && params.duration > 0)
				effect.duration = params.duration;
			
			var center:Point = new Point(0, 0);
			if(params.center_x)
				center.x = params.center_x;
			if(params.center_y)
				center.y = params.center_y;			
			effect.center = center;
			
			return effect;
		}
		
		/**
		 * Returns a <code>Spotlight</code> transition depending on a string type
		 * and a list of parameters.
		 */
		public static function getSpotlight(params:* = null):Spotlight
		{
			var effect:Spotlight = new Spotlight();
			
			effect.easer = EaserUtils.getEaser(params.easer);
			
			if(params.duration && params.duration > 0)
				effect.duration = params.duration;
			
			var center:Point = new Point(0, 0);
			if(params.center_x)
				center.x = params.center_x;
			if(params.center_y)
				center.y = params.center_y;			
			effect.center = center;
			
			return effect;
		}
		
		/**
		 * Returns a <code>Push</code> transition depending on a string type
		 * and a list of parameters.
		 */
		public static function getPush(params:* = null):Push
		{
			var effect:Push = new Push();
			
			effect.direction = params.direction;
			effect.easer = EaserUtils.getEaser(params.easer);
			
			if(params.duration && params.duration > 0)
				effect.duration = params.duration;
			
			return effect;
		}
	}
}